import request, {Method} from '@/plugins/request.js';

/**
 * 清空購物車
 */
export function clearCart() {
    return request({
        url: '/buyer/trade/carts',
        method: Method.DELETE,
        needToken: true
    });
}

/**
 * 获取購物車頁面購物車詳情
 */
export function cartGoodsAll() {
    return request({
        url: '/buyer/trade/carts/all',
        method: Method.GET,
        needToken: true
    });
}

/**
 * 获取購物車商品數量
 */
export function cartCount() {
    return request({
        url: '/buyer/trade/carts/count',
        method: Method.GET,
        needToken: true
    });
}

/**
 * 获取结算頁面購物車詳情
 */
export function cartGoodsPay(params) {
    return request({
        url: '/buyer/trade/carts/checked',
        method: Method.GET,
        needToken: true,
        params
    });
}

/**
 * 向購物車添加一个商品
 * @param skuId skuId
 * @param  num  购买數量
 */
export function addCartGoods(params) {
    return request({
        url: '/buyer/trade/carts',
        method: Method.POST,
        needToken: true,
        params
    });
}

/**
 * 创建交易
 * @param client 客戶端：H5/移動端 PC/PC端,WECHAT_MP/小程序端,APP/移動应用端
 * @param way 購物車购买：CART/立即购买：BUY_NOW / 積分购买：POINT
 * @param remark 备注  非必填
 */
export function createTrade(data) {
    return request({
        url: '/buyer/trade/carts/create/trade',
        method: Method.POST,
        needToken: true,
        headers: {'Content-Type': 'application/json'},
        data
    });
}

//结算，修改商品库存
export function stock(data) {
    return request({
        url: '/buyer/trade/carts/create/stock',
        method: Method.POST,
        needToken: true,
        headers: {'Content-Type': 'application/json'},
        data
    });
}


/**
 * 選擇
 * @param memberCouponId id
 * @param way 購物車购买：CART/立即购买：BUY_NOW/ 積分购买：POINT
 * @param used 使用true 弃用 false
 */
export function selectCoupon(params) {
    return request({
        url: '/buyer/trade/carts/select/coupon',
        method: Method.GET,
        needToken: true,
        params
    });
}

/**
 * 可用數量
 */
export function couponNum(params) {
    return request({
        url: '/buyer/trade/carts/coupon/num',
        method: Method.GET,
        needToken: true,
        params
    });
}

/**
 * 選擇收貨地址
 * @param shippingAddressId 地址id
 * @param way 購物車類型
 */
export function selectAddr(params) {
    return request({
        url: `/buyer/trade/carts/shippingAddress`,
        method: Method.GET,
        needToken: true,
        params
    });
}

/**
 * 選中購物車所有商品
 * @param checked 设置選中 0，1
 */
export function setCheckedAll(params) {
    return request({
        url: `/buyer/trade/carts/sku/checked`,
        method: Method.POST,
        needToken: true,
        params
    });
}

/**
 * 批量设置某商家的商品为選中或不選中
 * @param checked 是否選中
 * @param storeId   商家id
 */
export function setCheckedSeller(params) {
    return request({
        url: `/buyer/trade/carts/store/${params.storeId}`,
        method: Method.POST,
        needToken: true,
        params
    });
}

/**
 * 選中購物車中單个产品
 * @param skuId 产品id
 * @param checked 设置選中0，1
 */
export function setCheckedGoods(params) {
    return request({
        url: `/buyer/trade/carts/sku/checked/${params.skuId}`,
        method: Method.POST,
        needToken: true,
        params
    });
}

/**
 * 更新購物車中單个产品數量
 * @param skuId 产品id
 * @param num   产品數量
 */
export function setCartGoodsNum(params) {
    return request({
        url: `/buyer/trade/carts/sku/num/${params.skuId}`,
        method: Method.POST,
        needToken: true,
        params
    });
}

/**
 * 删除購物車中一个或多个产品
 * @param skuIds 产品id數组
 */
export function delCartGoods(params) {
    return request({
        url: `/buyer/trade/carts/sku/remove`,
        method: Method.DELETE,
        needToken: true,
        params
    });
}

/**
 * 選擇配送方式
 * @param shippingMethod SELF_PICK_UP(自提),LOCAL_TOWN_DELIVERY(同城配送),LOGISTICS(物流)
 * @param way 购物方式
 */
export function shippingMethod(params) {
    return request({
        url: `/buyer/trade/carts/shippingMethod`,
        method: Method.GET,
        needToken: true,
        params
    });
}

/**
 * 選擇發票
 * @param receiptId 發票Id
 * @param way 购物方式
 */
export function receiptSelect(params) {
    return request({
        url: `/buyer/trade/carts/select/receipt`,
        method: Method.GET,
        needToken: true,
        params
    });
}

/**
 * 获取全部配送方式
 */
export function shippingMethodList(params) {
    return request({
        url: `/buyer/trade/carts/shippingMethodList`,
        method: Method.GET,
        needToken: true,
        params: params,
    });
}

/**
 * 获取全部配送方式
 */
export function storeAddressList(params) {
    return request({
        url: `/buyer/store/address/shippingMethodList`,
        method: Method.GET,
        needToken: true,
        params: params,
    });
}

/**
 * 设置自提地址ID
 * @param addressId
 */
export function setStoreAddressId(storeAddressId, way) {
    return request({
        url: `/buyer/trade/carts/storeAddress?storeAddressId=${storeAddressId}&way=${way}`,
        method: Method.GET,
        needToken: true,
    });
}

/**
 * 提交配送方式
 * @param params
 */
export function setShipMethod(params) {
    return request({
        url: "/buyer/trade/carts/shippingMethod",
        method: Method.PUT,
        needToken: true,
        params,
    });
}
